package session1.examples.chap3;

import session1.test.threadTest.test1.Main;

public class Eg1 {
	public static enum MyEnum{Teacher,Student};
	public static final String[] names={"Mr.Wang","Zhang"};
	public static void main(String[] args) {
		Lecturing teacher=new Lecturing(names[MyEnum.Teacher.ordinal()]),
				student=new Lecturing(names[MyEnum.Student.ordinal()]);
		teacher.add(student);
		teacher.start();	student.start();
		try{student.join();	teacher.join();}
		catch (InterruptedException e){System.out.println("!");}
	}
}
class Lecturing extends Thread{
	public void add(Lecturing stu) {
		this.stu = stu;
	}
	@Override
	public void run() {
		String stu=Thread.currentThread().getName();
		if(stu.equals
				(Eg1.names[Eg1.MyEnum.Teacher.ordinal()])
		)
			for(int i=0;i<3;i++){
				System.out.println("Class Begins Now!")	;
				try {	Thread.sleep(1000);		}
				catch (	InterruptedException e)
				{		System.out.println(e.getMessage());	}
				this.stu.interrupt();
			}
		else if (stu.equals
				(Eg1.names[Eg1.MyEnum.Student.ordinal()])
		) {
			System.out.println(stu+": The teacher has not arrived, so just have another snap.");
			try {	Thread.sleep(1000*60*20);	}
			catch (InterruptedException e)
			{	System.out.println(stu+": Has the class begun when I has not been awake?");	}
		}
	}

	Lecturing stu;

	public Lecturing(String name) {
		super(name);
	}

}